package com.link.base.base.accnt.service;


import com.link.base.base.accnt.dao.mybatis.mapper.AccountImpMapper;
import com.link.base.base.accnt.model.AccountTemp;
import com.link.base.user.model.CoreUser;
import com.link.core.basic.dao.mapper.BasicMapper;
import com.link.core.basic.model.CallParam;
import com.link.core.basic.service.BasicServiceException;
import com.link.core.basic.service.BasicServiceImpl;
import com.link.core.util.UserUtil;
import com.link.core.cllog.LCLogger;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
/**
 * Copyright  hande Company. All Rights Reserved.
 *
 * @author  unknwon
 * @date:   2018/11/7 15:45
 * @version 1.0
 */

@Service
public class AccountImpServiceImpl extends BasicServiceImpl<AccountTemp> implements AccountImpService {

    @Resource
    private AccountImpMapper accountImpMapper;

    @Override
    public BasicMapper<AccountTemp> getBasicMapper() throws Exception {

        return accountImpMapper;
    }

    /**
     * 检验客户字段是否有效正确
     * @param record
     * @throws BasicServiceException
     */
    @Override
    @Transactional(rollbackFor = BasicServiceException.class)
    public void runAccountCheck(CallParam record) throws BasicServiceException {
        try {
            CoreUser user = UserUtil.getUser();
            record.setParam1(user.getId());
            accountImpMapper.runAccountCheck(record);
        } catch (Exception e) {
            LCLogger.withException(e);
            throw new BasicServiceException(e.getMessage());
        }
    }

    /**
     * 插入到客户
     * @param record
     * @throws BasicServiceException
     */
    @Override
    @Transactional(rollbackFor = BasicServiceException.class)
    public void runNewAccountForimp(CallParam record) throws BasicServiceException {
        try {
            CoreUser user = UserUtil.getUser();
            record.setParam1(user.getId());
            accountImpMapper.runAccountCheck(record);
            accountImpMapper.runNewAccountForimp(record);
        } catch (Exception e) {
            LCLogger.withException(e);
            throw new BasicServiceException(e.getMessage());
        }
    }
}
